import logging
from meiduo_mall.libs.yuntongxun.sms import CCP
from celery_tasks.main import app

logger = logging.getLogger('django')

# 验证码短信模板
SMS_CODE_TEMP_ID = 1

@app.task(name='send_sms_code')
def send_sms_code(mobile, code, expires):
    # 发送短信验证码
    result = -1
    try:
        result = CCP().send_template_sms(mobile,[code, expires], SMS_CODE_TEMP_ID)
    except Exception as e:
        logging.error("手机号码%s发送短信验证码异常"%mobile)
    print(result)
    if result == -1:
        logger.warning('发送短信验证码失败')
    logging.info('发送短信验证码成功')